package com.workflow.itrun.controller;

import com.github.pagehelper.PageInfo;
import com.workflow.itrun.dto.RequestDTO;
import com.workflow.itrun.entity.ItRequest;
import com.workflow.itrun.service.RequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class RequestController {

    @Autowired
    private RequestService requestService;

    @RequestMapping(value = "/get-requestList",method = RequestMethod.GET)
    @ResponseBody
    public  PageInfo<ItRequest> selectRequestList(Integer pageIndex, Integer pageSize){
        PageInfo<ItRequest> requestPageInfo = requestService.selectRequestList(pageIndex,pageSize);
        return requestPageInfo;
    }
    @RequestMapping(value = "/request/save-request",method = RequestMethod.POST)
    @ResponseBody
    public ItRequest saveRequest (@RequestBody RequestDTO requestDTO){
        ItRequest request =requestService.saveRequest(requestDTO);
        return request;
    }

    @RequestMapping(value = "/request/merge-request",method = RequestMethod.POST)
    @ResponseBody
    public ItRequest mergeRequest (@RequestBody RequestDTO requestDTO){
        ItRequest request =requestService.mergeRequest(requestDTO);
        return request;
    }

    @RequestMapping(value = "/request/delete-request",method = RequestMethod.POST)
    @ResponseBody
    public Integer deleteRequest (@RequestBody List<Integer> ids){

        requestService.deleteRequest(ids);
        return 1;
    }
}
